package com.uum.blog.controller;


import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.uum.blog.pojo.entity.Comment;
import com.uum.blog.pojo.vo.CommentVO;
import com.uum.blog.service.CommentService;
import com.uum.common.core.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@Api(tags = "评论接口")
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    private final CommentService commentService;

    @ApiOperation(value = "添加评论")
    @PostMapping("add/{currentPage}/{pageSize}")
    public Result addComment(@RequestBody Comment comment, @PathVariable Integer currentPage, @PathVariable Integer pageSize) {
        List<CommentVO> commentList = commentService.addComment(comment);
        List<CommentVO> page = CollUtil.page(0, currentPage * pageSize, commentList);
        return Result.success(page);
    }

    @ApiOperation(value = "删除评论")
    @DeleteMapping("delete/{commentId}/{blogId}")
    public Result delComment(@PathVariable Long commentId, @PathVariable Long blogId) {
        List<CommentVO> result = commentService.deleteComment(commentId, blogId);
        return Result.success(result);
    }
}

